package study.proxy;  
  
import java.lang.reflect.Proxy;
  
public class ProxyBasicDemo {  
  
    public static void main(String[] args) throws Exception {  
  
        // 这里不是面向接口的编程  
        MyInterceptor handler = new MyInterceptor();  
        handler.setTarget(new RealObject());  
          
//        Class<?> proxyClass = Proxy.getProxyClass(RealInterface.class  
//                .getClassLoader(), RealInterface.class);  
  
        RealInterface proxyInstance = (RealInterface) Proxy.newProxyInstance(RealInterface.class.getClassLoader(), new Class[]{RealInterface.class}, handler);
//        RealInterface proxyObject = (RealInterface) proxyClass.getConstructor(  
//                new Class[] { InvocationHandler.class }).newInstance(  
//                new Object[] { handler });  
//          
//        proxyObject.sayHello();  
        
        proxyInstance.sayHello();
    }  
  
}  